<?php
/**
 * MysqlDumpAction.class.php
 * mysql导出数据
 *@author zz
 *@version 1
 *@since 2015-9-21
 */
header("Content-type: text/html; charset=utf-8");
ini_set("memory_limit","4000M");
ini_set('max_execution_time', '0');
Class MysqlDumpAction 
{
	Public function index(){
	    
	}	
	
	//dump hezu info 表数据
	public function hezu_info_dump(){
	    $sell_gov = M('house_hezu_info');
	    $sell_gov_count=$sell_gov->count();
	    $page_count=1000;
	    for($i=0;$i<=($sell_gov_count/$page_count);$i++){
	        $house_list=array();
	        /**
	         * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
	         * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
	         * house_kitchen,owner_name,owner_phone,source,source_url, 5
	         * house_totalarea,borough_id,borough_name 3
	         *
	        * */
	        $house_list=$sell_gov->limit($i*$page_count,$page_count)->field('id,gov_id')->select();
	        foreach($house_list as $key=>$value){
	            //                 $format_out=implode("\t",$value);
	            //                 echo $format_out."\n";
	            // 	            echo json_encode($value)."\n";
	            echo $value['id']."\t".$value['gov_id']."\n";
	        }
	        sleep(1);
	    }
	
	}
	//dump tests_sell_info 表数据
	
	public function test_sell_info_dump(){
	    $sell_gov = M('tests_sell_info');
	    $sell_gov_count=$sell_gov->count();
	    $page_count=1000;
	    for($i=0;$i<=($sell_gov_count/$page_count);$i++){
	        $house_list=array();
	        /**
	         * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
	         * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
	         * house_kitchen,owner_name,owner_phone,source,source_url, 5
	         * house_totalarea,borough_id,borough_name 3
	         *
	        * */
	        $house_list=$sell_gov->limit($i*$page_count,$page_count)->field('id,gov_id')->select();
	        foreach($house_list as $key=>$value){
	            //                 $format_out=implode("\t",$value);
	            //                 echo $format_out."\n";
	            // 	            echo json_encode($value)."\n";
	            echo $value['id']."\t".$value['gov_id']."\n";
	        }
	        sleep(1);
	    }
	
	}
	
	//dump rent info 表数据
	public function rent_info_dump(){
	    $sell_gov = M('house_rent_info');
	    $sell_gov_count=$sell_gov->count();
	    $page_count=1000;
	    for($i=0;$i<=($sell_gov_count/$page_count);$i++){
	        $house_list=array();
	        /**
	         * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
	         * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
	         * house_kitchen,owner_name,owner_phone,source,source_url, 5
	         * house_totalarea,borough_id,borough_name 3
	         *
	        * */
	        $house_list=$sell_gov->limit($i*$page_count,$page_count)->field('id,gov_id')->select();
	        foreach($house_list as $key=>$value){
	            //                 $format_out=implode("\t",$value);
	            //                 echo $format_out."\n";
	            // 	            echo json_encode($value)."\n";
	            echo $value['id']."\t".$value['gov_id']."\n";
	        }
	        sleep(1);
	    }
	     
	}
	//dump sell info表数据
	public function sell_info_field_dump(){
	    $sell_gov = M('house_sell_info');
	    $sell_gov_count=$sell_gov->count();
	    $page_count=1000;
	    for($i=0;$i<=($sell_gov_count/$page_count);$i++){
	        $house_list=array();
	        /**
	         * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
	         * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
	         * house_kitchen,owner_name,owner_phone,source,source_url, 5
	         * house_totalarea,borough_id,borough_name 3
	         *
	        * */
	        $house_list=$sell_gov->limit($i*$page_count,$page_count)->field('id,gov_id')->select();
	        foreach($house_list as $key=>$value){
	            //                 $format_out=implode("\t",$value);
	            //                 echo $format_out."\n";
	            // 	            echo json_encode($value)."\n";
	            echo $value['id']."\t".$value['gov_id']."\n";
	        }
	        sleep(1);
	    }
	     
	}
	//dump sell info表数据
	public function sell_info_dump(){
	    $sell_gov = M('house_sell_info');
	    $sell_gov_count=$sell_gov->count();
	    $page_count=1000;
	    for($i=0;$i<=($sell_gov_count/$page_count);$i++){
	        $house_list=array();
	        /**
	         * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
	         * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
	         * house_kitchen,owner_name,owner_phone,source,source_url, 5
	         * house_totalarea,borough_id,borough_name 3
	         *
	        * */
	        //$house_list=$sell_gov->limit($i*$page_count,$page_count)->select();
	        $house_list = $sell_gov->query("select * from house_sell_info group by id having(count(*)=1) limit ".$i*$page_count.",".$page_count.";");
	        foreach($house_list as $key=>$value){
	            //                 $format_out=implode("\t",$value);
	            //                 echo $format_out."\n";
	            echo json_encode($value)."\n";
	        }
	        sleep(0.1);
	    }
	    
	}
	
	//dump sell_gov info表数据
        public function sell_gov_dump_nj(){
            $file = fopen("/alidata/server/hadoop/data/house_sell_gov_nj_".date("Ymd",strtotime("-1 day")), "w") or die("Unable to open file!");
           $sell_gov = M('house_sell_gov','','mysql://zhuge:zhuge1116@182.92.96.120:3306/spider_nj');
            $sell_gov_count=$sell_gov->count();
            $page_count=1000;

            for($i=0;$i<=($sell_gov_count/$page_count);$i++){
                $house_list=array();
                /**
                 * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
                 * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
                 * house_kitchen,owner_name,owner_phone,source,source_url, 5
                 * house_totalarea,borough_id,borough_name 3
                 *
                * */
                $house_list=$sell_gov->limit($i*$page_count,$page_count)->select();
                foreach($house_list as $key=>$value){
                    //                 $format_out=implode("\t",$value);
                    //                 echo $format_out."\n";

                   // echo json_encode($value)."\n";
                    $txt=json_encode($value)."\n";
                    fwrite($file, $txt);
                }//fclose($file);die;
                sleep(0.1);
            }
            fclose($file);
        }
	
	//dump sell_gov info表数据
	public function sell_gov_dump_sh(){
	    $file = fopen("/alidata/server/hadoop/data/house_sell_gov_sh_".date("Ymd",strtotime("-1 day")), "w") or die("Unable to open file!");
	   $sell_gov = M('house_sell_gov','','mysql://zhuge:zhuge1116@182.92.96.120:3306/spider_sh');
		//$sell_gov=M('test1_1');
	    $sell_gov_count=$sell_gov->count();
	    $page_count=1000;
	    
	    for($i=0;$i<=($sell_gov_count/$page_count);$i++){
	        $house_list=array();
	        /**
	         * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
	         * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
	         * house_kitchen,owner_name,owner_phone,source,source_url, 5
	         * house_totalarea,borough_id,borough_name 3
	         *
	        * */
	        $house_list=$sell_gov->limit($i*$page_count,$page_count)->select();
	        foreach($house_list as $key=>$value){
	            //                 $format_out=implode("\t",$value);
	            //                 echo $format_out."\n";
	            
	           // echo json_encode($value)."\n";
	            $txt=json_encode($value)."\n";
	            fwrite($file, $txt);
	        }//fclose($file);die;
	        sleep(0.1);
	    }
	    fclose($file);
	}
	
	//dump sell_gov info表数据
        public function sell_gov_dump_sz(){
            $file = fopen("/alidata/server/hadoop/data/house_sell_gov_sz_".date("Ymd",strtotime("-1 day")), "w") or die("Unable to open file!");
           $sell_gov = M('house_sell_gov','','mysql://zhuge:zhuge1116@182.92.96.120:3306/spider_sz');
            $sell_gov_count=$sell_gov->count();
            $page_count=1000;

            for($i=0;$i<=($sell_gov_count/$page_count);$i++){
                $house_list=array();
                /**
                 * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
                 * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
                 * house_kitchen,owner_name,owner_phone,source,source_url, 5
                 * house_totalarea,borough_id,borough_name 3
                 *
                * */
                $house_list=$sell_gov->limit($i*$page_count,$page_count)->select();
                foreach($house_list as $key=>$value){
                    //                 $format_out=implode("\t",$value);
                    //                 echo $format_out."\n";

                   // echo json_encode($value)."\n";
                    $txt=json_encode($value)."\n";
                    fwrite($file, $txt);
                }//fclose($file);die;
                sleep(0.1);
            }
            fclose($file);
        }
	
	//dump sell_gov info表数据
        public function sell_gov_dump_gz(){
            $file = fopen("/alidata/server/hadoop/data/house_sell_gov_gz_".date("Ymd",strtotime("-1 day")), "w") or die("Unable to open file!");
           $sell_gov = M('house_sell_gov','','mysql://zhuge:zhuge1116@182.92.96.120:3306/spider_gz');
            $sell_gov_count=$sell_gov->count();
            $page_count=1000;

            for($i=0;$i<=($sell_gov_count/$page_count);$i++){
                $house_list=array();
                /**
                 * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
                 * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
                 * house_kitchen,owner_name,owner_phone,source,source_url, 5
                 * house_totalarea,borough_id,borough_name 3
                 *
                * */
                $house_list=$sell_gov->limit($i*$page_count,$page_count)->select();
                foreach($house_list as $key=>$value){
                    //                 $format_out=implode("\t",$value);
                    //                 echo $format_out."\n";

                   // echo json_encode($value)."\n";
                    $txt=json_encode($value)."\n";
                    fwrite($file, $txt);
                }//fclose($file);die;
                sleep(0.1);
            }
            fclose($file);
        }

	//dump sell_gov info表数据
        public function sell_gov_dump_bj(){
            $file = fopen("/alidata/server/hadoop/data/house_sell_gov_bj_".date("Ymd",strtotime("-1 day")), "w") or die("Unable to open file!");
           $sell_gov = M('house_sell_gov','','mysql://zhuge:zhuge1116@rds1tu038044m8zub4o7.mysql.rds.aliyuncs.com/spider');
            $sell_gov_count=$sell_gov->count();
            $page_count=1000;

            for($i=0;$i<=($sell_gov_count/$page_count);$i++){
                $house_list=array();
                /**
                 * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
                 * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
                 * house_kitchen,owner_name,owner_phone,source,source_url, 5
                 * house_totalarea,borough_id,borough_name 3
                 *
                * */
                $house_list=$sell_gov->limit($i*$page_count,$page_count)->select();
                foreach($house_list as $key=>$value){
                    //                 $format_out=implode("\t",$value);
                    //                 echo $format_out."\n";

                   // echo json_encode($value)."\n";
                    $txt=json_encode($value)."\n";
                    fwrite($file, $txt);
                }//fclose($file);die;
                sleep(0.1);
            }
            fclose($file);
        }

	//dump house_sell_gov表数据,格式：小区id、其他信息json
	public function sell_gov_test_reduce3_dump(){
	    //borough_id 129742
	    $where = array('borough_id'=>31955);
	    $sell_gov = M('house_sell_gov');
	    $sell_gov_count=$sell_gov->where($where)->count();
	    $page_count=1000;
	    for($i=0;$i<=($sell_gov_count/$page_count);$i++){
	        $house_list=array();
	        /**
	         * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
	         * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
	         * house_kitchen,owner_name,owner_phone,source,source_url, 5
	         * house_totalarea,borough_id,borough_name 3
	         *
	        * */
	        $house_list=$sell_gov->limit($i*$page_count,$page_count)->where($where)->select();
	        foreach($house_list as $key=>$value){
	            //                 $format_out=implode("\t",$value);
	            //                 echo $format_out."\n";
	            echo $value['borough_id']."\t".json_encode($value)."\n";
	        }
	        sleep(0.1);
	    }
	
	}
	//dump data from house_rent_gov ,1000条for test
	public function rent_gov_dump_bj(){
            $file = fopen("/alidata/server/hadoop/data/house_rent_gov_bj_".date("Ymd",strtotime("-1 day")), "w") or die("Unable to open file!");
           $rent_gov = M('house_rent_gov','','mysql://zhuge:zhuge1116@182.92.96.120:3306/spider');
            $rent_gov_count=$rent_gov->count();
            $page_count=100;

           // for($i=0;$i<=($rent_gov_count/$page_count);$i++){
                $house_list=array();
                /**
                 * id,house_title,house_price,cityarea_id,cityarea2_id,house_floor, 6
                 * house_topfloor,house_toward,house_room,house_hall,house_toilet, 5
                 * house_kitchen,owner_name,owner_phone,source,source_url, 5
                 * house_totalarea,borough_id,borough_name 3
                 *
                * */
				$i=0;
                $house_list=$rent_gov->limit($i*$page_count,$page_count)->select();
                foreach($house_list as $key=>$value){
                    //                 $format_out=implode("\t",$value);
                    //                 echo $format_out."\n";

                   // echo json_encode($value)."\n";
                    $txt=json_encode($value)."\n";
                    fwrite($file, $txt);
                }//fclose($file);die;
                sleep(0.1);
           // }
            fclose($file);
        }
	
}
